package smartcounters.androidclient.WebServices;

import java.util.LinkedList;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.os.Message;

import smartcounters.androidclient.model.AccountInfo;
import smartcounters.androidclient.model.AuthenticatedUserCredentials;
import smartcounters.androidclient.model.Fault;
import smartcounters.androidclient.model.eOperationsEnum;
import smartcounters.androidclient.model.UserInfo;

public class InformationReaderWebServiceClient implements OnResultReceiver{
	private LinkedList<OnResultReceiver> m_ResultReceivers;
	private String m_URL;
	
	public InformationReaderWebServiceClient(String i_ServerIP) {
		m_ResultReceivers = new LinkedList<OnResultReceiver>();
		
		m_URL = "http://" + i_ServerIP + ":50171/WebServices/InformationReaderWebService.asmx?WSDL";
	}
	
    public void GetUserInformationByID(AuthenticatedUserCredentials i_AuthenticatedUserCredentials, int i_UserID)
    {
    	String NAMESPACE = "http://smartcounters.org";
		String GET_SOAP_ACTION = "http://smartcounters.org/GetUserInformationByID";
		String GET_METHOD_NAME = "GetUserInformationByID";
		
		SoapObject request = new SoapObject(NAMESPACE, GET_METHOD_NAME);
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		
		SoapObject authenticatedUserIDObject = new SoapObject(NAMESPACE, "i_AuthenticatedUserID");
		authenticatedUserIDObject.addProperty("i_AuthenticatedUserID", i_AuthenticatedUserCredentials.getID());
		SoapObject authenticatedUserPasswordObject = new SoapObject(NAMESPACE, "i_AuthenticatedUserPassword");
		authenticatedUserPasswordObject.addProperty("i_AuthenticatedUserPassword", i_AuthenticatedUserCredentials.getPassword());
		SoapObject userIDObject = new SoapObject(NAMESPACE, "i_UserID");
		userIDObject.addProperty("i_UserID", i_UserID);
		
		request.addSoapObject(authenticatedUserIDObject);
		authenticatedUserIDObject.addSoapObject(authenticatedUserPasswordObject);
		authenticatedUserPasswordObject.addSoapObject(userIDObject);
		
		envelope.setOutputSoapObject(request);
		HttpTransportSE androidHttpTransport = new HttpTransportSE(m_URL);
		
		MessageHandler handler = new MessageHandler();
		handler.RegisterResultReceiver(this);
		WebMethodAsyncInvoker webMethodAsyncInvoker = new WebMethodAsyncInvoker(androidHttpTransport, GET_SOAP_ACTION, envelope, handler, eOperationsEnum.GetUserInformationByID);
		
		Thread thread = new Thread(webMethodAsyncInvoker);
		thread.start();
    }

    public void GetUserInformationByUsername(AuthenticatedUserCredentials i_AuthenticatedUserCredentials, String i_Username)
    {
    	String NAMESPACE = "http://smartcounters.org";
		String GET_SOAP_ACTION = "http://smartcounters.org/GetUserInformationByUsername";
		String GET_METHOD_NAME = "GetUserInformationByUsername";
		
		SoapObject request = new SoapObject(NAMESPACE, GET_METHOD_NAME);
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		
		SoapObject authenticatedUserIDObject = new SoapObject(NAMESPACE, "i_AuthenticatedUserID");
		authenticatedUserIDObject.addProperty("i_AuthenticatedUserID", i_AuthenticatedUserCredentials.getID());
		SoapObject authenticatedUserPasswordObject = new SoapObject(NAMESPACE, "i_AuthenticatedUserPassword");
		authenticatedUserPasswordObject.addProperty("i_AuthenticatedUserPassword", i_AuthenticatedUserCredentials.getPassword());
		SoapObject usernameObject = new SoapObject(NAMESPACE, "i_Username");
		usernameObject.addProperty("i_Username", i_Username);
		
		request.addSoapObject(authenticatedUserIDObject);
		authenticatedUserIDObject.addSoapObject(authenticatedUserPasswordObject);
		authenticatedUserPasswordObject.addSoapObject(usernameObject);
		
		envelope.setOutputSoapObject(request);
		HttpTransportSE androidHttpTransport = new HttpTransportSE(m_URL);
		
		MessageHandler handler = new MessageHandler();
		handler.RegisterResultReceiver(this);
		WebMethodAsyncInvoker webMethodAsyncInvoker = new WebMethodAsyncInvoker(androidHttpTransport, GET_SOAP_ACTION, envelope, handler, eOperationsEnum.GetUserInformationByUsername);
		
		Thread thread = new Thread(webMethodAsyncInvoker);
		thread.start();
    }

    public void GetAccountInformation(AuthenticatedUserCredentials i_AuthenticatedUserCredentials, int i_AccountID)
    {
    	String NAMESPACE = "http://smartcounters.org";
		String GET_SOAP_ACTION = "http://smartcounters.org/GetAccountInformation";
		String GET_METHOD_NAME = "GetAccountInformation";
		
		SoapObject request = new SoapObject(NAMESPACE, GET_METHOD_NAME);
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		
		SoapObject authenticatedUserIDObject = new SoapObject(NAMESPACE, "i_AuthenticatedUserID");
		authenticatedUserIDObject.addProperty("i_AuthenticatedUserID", i_AuthenticatedUserCredentials.getID());
		SoapObject authenticatedUserPasswordObject = new SoapObject(NAMESPACE, "i_AuthenticatedUserPassword");
		authenticatedUserPasswordObject.addProperty("i_AuthenticatedUserPassword", i_AuthenticatedUserCredentials.getPassword());
		SoapObject accountIDObject = new SoapObject(NAMESPACE, "i_AccountID");
		accountIDObject.addProperty("i_AccountID", i_AccountID);
		
		request.addSoapObject(authenticatedUserIDObject);
		authenticatedUserIDObject.addSoapObject(authenticatedUserPasswordObject);
		authenticatedUserPasswordObject.addSoapObject(accountIDObject);
		
		envelope.setOutputSoapObject(request);
		HttpTransportSE androidHttpTransport = new HttpTransportSE(m_URL);
		
		MessageHandler handler = new MessageHandler();
		handler.RegisterResultReceiver(this);
		WebMethodAsyncInvoker webMethodAsyncInvoker = new WebMethodAsyncInvoker(androidHttpTransport, GET_SOAP_ACTION, envelope, handler, eOperationsEnum.GetAccountInformation);
		
		Thread thread = new Thread(webMethodAsyncInvoker);
		thread.start();
    }

    public void GetAllAccounts(AuthenticatedUserCredentials i_AuthenticatedUserCredentials)
    {
    	String NAMESPACE = "http://smartcounters.org";
		String GET_SOAP_ACTION = "http://smartcounters.org/GetAllAccounts";
		String GET_METHOD_NAME = "GetAllAccounts";
		
		SoapObject request = new SoapObject(NAMESPACE, GET_METHOD_NAME);
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		
		SoapObject usernameObject = new SoapObject(NAMESPACE, "i_AuthenticatedUserID");
		usernameObject.addProperty("i_AuthenticatedUserID", i_AuthenticatedUserCredentials.getID());
		SoapObject passwordObject = new SoapObject(NAMESPACE, "i_AuthenticatedUserPassword");
		passwordObject.addProperty("i_AuthenticatedUserPassword", i_AuthenticatedUserCredentials.getPassword());
		
		request.addSoapObject(usernameObject);
		usernameObject.addSoapObject(passwordObject);
		
		envelope.setOutputSoapObject(request);
		HttpTransportSE androidHttpTransport = new HttpTransportSE(m_URL);
		
		MessageHandler handler = new MessageHandler();
		handler.RegisterResultReceiver(this);
		WebMethodAsyncInvoker webMethodAsyncInvoker = new WebMethodAsyncInvoker(androidHttpTransport, GET_SOAP_ACTION, envelope, handler, eOperationsEnum.GetAllAccounts);
		
		Thread thread = new Thread(webMethodAsyncInvoker);
		thread.start();
    }

    public void GetAllUsers(AuthenticatedUserCredentials i_AuthenticatedUserCredentials)
    {
    	String NAMESPACE = "http://smartcounters.org";
		String GET_SOAP_ACTION = "http://smartcounters.org/GetAllUsers";
		String GET_METHOD_NAME = "GetAllUsers";
		
		SoapObject request = new SoapObject(NAMESPACE, GET_METHOD_NAME);
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		
		SoapObject usernameObject = new SoapObject(NAMESPACE, "i_AuthenticatedUserID");
		usernameObject.addProperty("i_AuthenticatedUserID", i_AuthenticatedUserCredentials.getID());
		SoapObject passwordObject = new SoapObject(NAMESPACE, "i_AuthenticatedUserPassword");
		passwordObject.addProperty("i_AuthenticatedUserPassword", i_AuthenticatedUserCredentials.getPassword());
		
		request.addSoapObject(usernameObject);
		usernameObject.addSoapObject(passwordObject);
		
		envelope.setOutputSoapObject(request);
		HttpTransportSE androidHttpTransport = new HttpTransportSE(m_URL);
		
		MessageHandler handler = new MessageHandler();
		handler.RegisterResultReceiver(this);
		WebMethodAsyncInvoker webMethodAsyncInvoker = new WebMethodAsyncInvoker(androidHttpTransport, GET_SOAP_ACTION, envelope, handler, eOperationsEnum.GetAllUsers);
		
		Thread thread = new Thread(webMethodAsyncInvoker);
		thread.start();
    }

    public void IsUserExists(AuthenticatedUserCredentials i_AuthenticatedUserCredentials, String i_Username)
    {
    	String NAMESPACE = "http://smartcounters.org";
		String GET_SOAP_ACTION = "http://smartcounters.org/IsUserExists";
		String GET_METHOD_NAME = "IsUserExists";
		
		SoapObject request = new SoapObject(NAMESPACE, GET_METHOD_NAME);
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		
		SoapObject authenticatedUserIDObject = new SoapObject(NAMESPACE, "i_AuthenticatedUserID");
		authenticatedUserIDObject.addProperty("i_AuthenticatedUserID", i_AuthenticatedUserCredentials.getID());
		SoapObject authenticatedUserPasswordObject = new SoapObject(NAMESPACE, "i_AuthenticatedUserPassword");
		authenticatedUserPasswordObject.addProperty("i_AuthenticatedUserPassword", i_AuthenticatedUserCredentials.getPassword());
		SoapObject usernameObject = new SoapObject(NAMESPACE, "i_Username");
		usernameObject.addProperty("i_Username", i_Username);
		
		request.addSoapObject(authenticatedUserIDObject);
		authenticatedUserIDObject.addSoapObject(authenticatedUserPasswordObject);
		authenticatedUserPasswordObject.addSoapObject(usernameObject);
		
		request.addSoapObject(usernameObject);
		
		envelope.setOutputSoapObject(request);
		HttpTransportSE androidHttpTransport = new HttpTransportSE(m_URL);
		
		MessageHandler handler = new MessageHandler();
		handler.RegisterResultReceiver(this);
		WebMethodAsyncInvoker webMethodAsyncInvoker = new WebMethodAsyncInvoker(androidHttpTransport, GET_SOAP_ACTION, envelope, handler, eOperationsEnum.IsUserExists);
		
		Thread thread = new Thread(webMethodAsyncInvoker);
		thread.start();
    }

    public void IsAccountExistsWithoutApartment(AuthenticatedUserCredentials i_AuthenticatedUserCredentials, String i_Country, String i_City, String i_Street, int i_House)
    {
    	String NAMESPACE = "http://smartcounters.org";
		String GET_SOAP_ACTION = "http://smartcounters.org/IsAccountExistsWithoutApartment";
		String GET_METHOD_NAME = "IsAccountExistsWithoutApartment";
		
		SoapObject request = new SoapObject(NAMESPACE, GET_METHOD_NAME);
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		
		SoapObject authenticatedUserIDObject = new SoapObject(NAMESPACE, "i_AuthenticatedUserID");
		authenticatedUserIDObject.addProperty("i_AuthenticatedUserID", i_AuthenticatedUserCredentials.getID());
		SoapObject authenticatedUserPasswordObject = new SoapObject(NAMESPACE, "i_AuthenticatedUserPassword");
		authenticatedUserPasswordObject.addProperty("i_AuthenticatedUserPassword", i_AuthenticatedUserCredentials.getPassword());
		SoapObject countryObject = new SoapObject(NAMESPACE, "i_Country");
		countryObject.addProperty("i_Country", i_Country);
		SoapObject cityObject = new SoapObject(NAMESPACE, "i_City");
		cityObject.addProperty("i_City", i_City);
		SoapObject streetObject = new SoapObject(NAMESPACE, "i_Street");
		streetObject.addProperty("i_Street", i_Street);
		SoapObject houseObject = new SoapObject(NAMESPACE, "i_House");
		houseObject.addProperty("i_House", i_House);
		
		request.addSoapObject(authenticatedUserIDObject);
		authenticatedUserIDObject.addSoapObject(authenticatedUserPasswordObject);
		authenticatedUserPasswordObject.addSoapObject(countryObject);
		countryObject.addSoapObject(cityObject);
		cityObject.addSoapObject(streetObject);
		streetObject.addSoapObject(houseObject);
		
		envelope.setOutputSoapObject(request);
		HttpTransportSE androidHttpTransport = new HttpTransportSE(m_URL);
		
		MessageHandler handler = new MessageHandler();
		handler.RegisterResultReceiver(this);
		WebMethodAsyncInvoker webMethodAsyncInvoker = new WebMethodAsyncInvoker(androidHttpTransport, GET_SOAP_ACTION, envelope, handler, eOperationsEnum.IsAccountExistsWithoutApartment);
		
		Thread thread = new Thread(webMethodAsyncInvoker);
		thread.start();
    }

    public void IsAccountExistsWithApartment(AuthenticatedUserCredentials i_AuthenticatedUserCredentials, String i_Country, String i_City, String i_Street, int i_House, int i_Apartment)
    {
    	String NAMESPACE = "http://smartcounters.org";
		String GET_SOAP_ACTION = "http://smartcounters.org/IsAccountExistsWithApartment";
		String GET_METHOD_NAME = "IsAccountExistsWithApartment";
		
		SoapObject request = new SoapObject(NAMESPACE, GET_METHOD_NAME);
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		
		SoapObject authenticatedUserIDObject = new SoapObject(NAMESPACE, "i_AuthenticatedUserID");
		authenticatedUserIDObject.addProperty("i_AuthenticatedUserID", i_AuthenticatedUserCredentials.getID());
		SoapObject authenticatedUserPasswordObject = new SoapObject(NAMESPACE, "i_AuthenticatedUserPassword");
		authenticatedUserPasswordObject.addProperty("i_AuthenticatedUserPassword", i_AuthenticatedUserCredentials.getPassword());
		SoapObject countryObject = new SoapObject(NAMESPACE, "i_Country");
		countryObject.addProperty("i_Country", i_Country);
		SoapObject cityObject = new SoapObject(NAMESPACE, "i_City");
		cityObject.addProperty("i_City", i_City);
		SoapObject streetObject = new SoapObject(NAMESPACE, "i_Street");
		streetObject.addProperty("i_Street", i_Street);
		SoapObject houseObject = new SoapObject(NAMESPACE, "i_House");
		houseObject.addProperty("i_House", i_House);
		SoapObject apartmentObject = new SoapObject(NAMESPACE, "i_Apartment");
		apartmentObject.addProperty("i_Apartment", i_Apartment);
		
		request.addSoapObject(authenticatedUserIDObject);
		authenticatedUserIDObject.addSoapObject(authenticatedUserPasswordObject);
		authenticatedUserPasswordObject.addSoapObject(countryObject);
		countryObject.addSoapObject(cityObject);
		cityObject.addSoapObject(streetObject);
		streetObject.addSoapObject(houseObject);
		houseObject.addSoapObject(apartmentObject);
		
		envelope.setOutputSoapObject(request);
		HttpTransportSE androidHttpTransport = new HttpTransportSE(m_URL);
		
		MessageHandler handler = new MessageHandler();
		handler.RegisterResultReceiver(this);
		WebMethodAsyncInvoker webMethodAsyncInvoker = new WebMethodAsyncInvoker(androidHttpTransport, GET_SOAP_ACTION, envelope, handler, eOperationsEnum.IsAccountExistsWithApartment);
		
		Thread thread = new Thread(webMethodAsyncInvoker);
		thread.start();
    }

    public void GetFaultInformation(AuthenticatedUserCredentials i_AuthenticatedUserCredentials, int i_FaultID)
    {
    	String NAMESPACE = "http://smartcounters.org";
		String GET_SOAP_ACTION = "http://smartcounters.org/GetFaultInformation";
		String GET_METHOD_NAME = "GetFaultInformation";
		
		SoapObject request = new SoapObject(NAMESPACE, GET_METHOD_NAME);
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		
		SoapObject authenticatedUserIDObject = new SoapObject(NAMESPACE, "i_AuthenticatedUserID");
		authenticatedUserIDObject.addProperty("i_AuthenticatedUserID", i_AuthenticatedUserCredentials.getID());
		SoapObject authenticatedUserPasswordObject = new SoapObject(NAMESPACE, "i_AuthenticatedUserPassword");
		authenticatedUserPasswordObject.addProperty("i_AuthenticatedUserPassword", i_AuthenticatedUserCredentials.getPassword());
		SoapObject faultIDObject = new SoapObject(NAMESPACE, "i_FaultID");
		faultIDObject.addProperty("i_FaultID", i_FaultID);
		
		request.addSoapObject(authenticatedUserIDObject);
		authenticatedUserIDObject.addSoapObject(authenticatedUserPasswordObject);
		authenticatedUserPasswordObject.addSoapObject(faultIDObject);
		
		envelope.setOutputSoapObject(request);
		HttpTransportSE androidHttpTransport = new HttpTransportSE(m_URL);
		
		MessageHandler handler = new MessageHandler();
		handler.RegisterResultReceiver(this);
		WebMethodAsyncInvoker webMethodAsyncInvoker = new WebMethodAsyncInvoker(androidHttpTransport, GET_SOAP_ACTION, envelope, handler, eOperationsEnum.GetFaultInformation);
		
		Thread thread = new Thread(webMethodAsyncInvoker);
		thread.start();
    }

    public void GetAllOpenFaults(AuthenticatedUserCredentials i_AuthenticatedUserCredentials)
    {
    	String NAMESPACE = "http://smartcounters.org";
		String GET_SOAP_ACTION = "http://smartcounters.org/GetAllOpenFaults";
		String GET_METHOD_NAME = "GetAllOpenFaults";
		
		SoapObject request = new SoapObject(NAMESPACE, GET_METHOD_NAME);
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		
		SoapObject authenticatedUserIDObject = new SoapObject(NAMESPACE, "i_AuthenticatedUserID");
		authenticatedUserIDObject.addProperty("i_AuthenticatedUserID", i_AuthenticatedUserCredentials.getID());
		SoapObject authenticatedUserPasswordObject = new SoapObject(NAMESPACE, "i_AuthenticatedUserPassword");
		authenticatedUserPasswordObject.addProperty("i_AuthenticatedUserPassword", i_AuthenticatedUserCredentials.getPassword());
		
		request.addSoapObject(authenticatedUserIDObject);
		authenticatedUserIDObject.addSoapObject(authenticatedUserPasswordObject);
		
		envelope.setOutputSoapObject(request);
		HttpTransportSE androidHttpTransport = new HttpTransportSE(m_URL);
		
		MessageHandler handler = new MessageHandler();
		handler.RegisterResultReceiver(this);
		WebMethodAsyncInvoker webMethodAsyncInvoker = new WebMethodAsyncInvoker(androidHttpTransport, GET_SOAP_ACTION, envelope, handler, eOperationsEnum.GetAllOpenFaults);
		
		Thread thread = new Thread(webMethodAsyncInvoker);
		thread.start();
    }

    public void GetAllOpenFaultsForAccount(AuthenticatedUserCredentials i_AuthenticatedUserCredentials, int i_AccountID)
    {
    	String NAMESPACE = "http://smartcounters.org";
		String GET_SOAP_ACTION = "http://smartcounters.org/GetAllOpenFaultsForAccount";
		String GET_METHOD_NAME = "GetAllOpenFaultsForAccount";
		
		SoapObject request = new SoapObject(NAMESPACE, GET_METHOD_NAME);
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		
		SoapObject authenticatedUserIDObject = new SoapObject(NAMESPACE, "i_AuthenticatedUserID");
		authenticatedUserIDObject.addProperty("i_AuthenticatedUserID", i_AuthenticatedUserCredentials.getID());
		SoapObject authenticatedUserPasswordObject = new SoapObject(NAMESPACE, "i_AuthenticatedUserPassword");
		authenticatedUserPasswordObject.addProperty("i_AuthenticatedUserPassword", i_AuthenticatedUserCredentials.getPassword());
		SoapObject accountIDObject = new SoapObject(NAMESPACE, "i_AccountID");
		accountIDObject.addProperty("i_AccountID", i_AccountID);
		
		request.addSoapObject(authenticatedUserIDObject);
		authenticatedUserIDObject.addSoapObject(authenticatedUserPasswordObject);
		authenticatedUserPasswordObject.addSoapObject(accountIDObject);
		
		envelope.setOutputSoapObject(request);
		HttpTransportSE androidHttpTransport = new HttpTransportSE(m_URL);
		
		MessageHandler handler = new MessageHandler();
		handler.RegisterResultReceiver(this);
		WebMethodAsyncInvoker webMethodAsyncInvoker = new WebMethodAsyncInvoker(androidHttpTransport, GET_SOAP_ACTION, envelope, handler, eOperationsEnum.GetAllOpenFaultsForAccount);
		
		Thread thread = new Thread(webMethodAsyncInvoker);
		thread.start();
    }
	
	public void RegisterResultReceiver(OnResultReceiver i_ResultReceiver ) {
		m_ResultReceivers.add(i_ResultReceiver);
	}
	
	protected void OnResultReceived(Message i_Msg){
		if (i_Msg.obj instanceof ConnectionError){
			return;
		}
		
		SoapObject resultsRequestSOAP = (SoapObject) i_Msg.obj;
		if (resultsRequestSOAP.getPropertyCount() == 0) {
			i_Msg.obj = null;
		}
		else{
			if (eOperationsEnum.values()[i_Msg.what] == eOperationsEnum.GetUserInformationByID){
				SoapObject soapObject = (SoapObject)resultsRequestSOAP.getProperty(0);
				i_Msg.obj = UserInfo.CreateFromSoapObject(soapObject);
			}
			else if (eOperationsEnum.values()[i_Msg.what] == eOperationsEnum.GetUserInformationByUsername){
				SoapObject soapObject = (SoapObject)resultsRequestSOAP.getProperty(0);
				i_Msg.obj = UserInfo.CreateFromSoapObject(soapObject);
			}
			else if (eOperationsEnum.values()[i_Msg.what] == eOperationsEnum.GetAccountInformation){
				SoapObject soapObject = (SoapObject)resultsRequestSOAP.getProperty(0);
				i_Msg.obj = AccountInfo.CreateFromSoapObject(soapObject);
			}
			else if (eOperationsEnum.values()[i_Msg.what] == eOperationsEnum.GetAllAccounts){
				SoapObject array = (SoapObject)resultsRequestSOAP.getProperty(0);
				AccountInfo[] accounts = new AccountInfo[array.getPropertyCount()];
				
				for(int i = 0; i < array.getPropertyCount(); i++){
					SoapObject soapObject = (SoapObject)array.getProperty(i);
					accounts[i] = AccountInfo.CreateFromSoapObject(soapObject);
				}
				
				i_Msg.obj = accounts;
			}
			else if (eOperationsEnum.values()[i_Msg.what] == eOperationsEnum.GetAllUsers){
				SoapObject array = (SoapObject)resultsRequestSOAP.getProperty(0);
				UserInfo[] users = new UserInfo[array.getPropertyCount()];
				
				for(int i = 0; i < array.getPropertyCount(); i++){
					SoapObject soapObject = (SoapObject)array.getProperty(i);
					users[i] = UserInfo.CreateFromSoapObject(soapObject);
				}
				
				i_Msg.obj = users;
			}
			else if (eOperationsEnum.values()[i_Msg.what] == eOperationsEnum.IsUserExists){
				i_Msg.obj = Boolean.parseBoolean(resultsRequestSOAP.getProperty(0).toString());
			}
			else if (eOperationsEnum.values()[i_Msg.what] == eOperationsEnum.IsAccountExistsWithoutApartment){
				i_Msg.obj = Boolean.parseBoolean(resultsRequestSOAP.getProperty(0).toString());
			}
			else if (eOperationsEnum.values()[i_Msg.what] == eOperationsEnum.IsAccountExistsWithApartment){
				i_Msg.obj = Boolean.parseBoolean(resultsRequestSOAP.getProperty(0).toString());
			}
			else if (eOperationsEnum.values()[i_Msg.what] == eOperationsEnum.GetFaultInformation){
				SoapObject soapObject = (SoapObject)resultsRequestSOAP.getProperty(0);
				i_Msg.obj = Fault.CreateFromSoapObject(soapObject);
			}
			else if (eOperationsEnum.values()[i_Msg.what] == eOperationsEnum.GetAllOpenFaults){
				SoapObject array = (SoapObject)resultsRequestSOAP.getProperty(0);
				Fault[] faults = new Fault[array.getPropertyCount()];
				
				for(int i = 0; i < array.getPropertyCount(); i++){
					SoapObject soapObject = (SoapObject)array.getProperty(i);
					faults[i] = Fault.CreateFromSoapObject(soapObject);
				}
				
				i_Msg.obj = faults;
			}
			else if (eOperationsEnum.values()[i_Msg.what] == eOperationsEnum.GetAllOpenFaultsForAccount){
				SoapObject array = (SoapObject)resultsRequestSOAP.getProperty(0);
				Fault[] faults = new Fault[array.getPropertyCount()];
				
				for(int i = 0; i < array.getPropertyCount(); i++){
					SoapObject soapObject = (SoapObject)array.getProperty(i);
					faults[i] = Fault.CreateFromSoapObject(soapObject);
				}
				
				i_Msg.obj = faults;
			}
		}
		
		for (OnResultReceiver resultReceiver : m_ResultReceivers) {
			resultReceiver.ReceiveResult(i_Msg);
		}
	}

	public void ReceiveResult(Message i_Msg) {
		OnResultReceived(i_Msg);
	}
}